/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.swirrel.listener;

import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.swirrel.util.MethodCall;
import org.swirrel.util.SwirrelException;

/**
 *
 * @author Gronau
 */
public class SwirrelDocumentListener extends AbstractSwirrelListener implements DocumentListener {

    private final MethodCall insertUpdateCall;
    private final MethodCall removeUpdateCall;
    private final MethodCall changedUpdateCall;

       public SwirrelDocumentListener(
            MethodCall insertUpdateCall,
            MethodCall removeUpdateCall,
            MethodCall changedUpdateCall) {
        this.insertUpdateCall = insertUpdateCall;
        this.removeUpdateCall = removeUpdateCall;
        this.changedUpdateCall = changedUpdateCall;
        if (!checkSignature(insertUpdateCall, DocumentEvent.class) ||
            !checkSignature(removeUpdateCall, DocumentEvent.class) ||
            !checkSignature(changedUpdateCall, DocumentEvent.class)) {
            throw new SwirrelException("Method must have none or one DocumentEvent argument");
        }
    }

    public void insertUpdate(DocumentEvent e) {
        call(insertUpdateCall, e);
    }

    public void removeUpdate(DocumentEvent e) {
        call(removeUpdateCall, e);
    }

    public void changedUpdate(DocumentEvent e) {
        call(changedUpdateCall, e);
    }

}
